<?php
// 设置脚本类型
header('content-type:application/json;charset=UTF-8');

$connect = mysqli_connect('127.0.0.1', 'root', 'root', 'stuent');
$sql = "select dept.name, count(*) as total 
FROM dept
join emp on dept.dept_id = emp.dept_id
group by emp.dept_id";
$query = mysqli_query($connect, $sql);
$data = mysqli_fetch_all($query);
// print_r($data);

$xData = [];
$yData = [];
foreach ($data as $value) {
    $xData[] = $value['0'];
    $yData[] = $value['1'];
}
echo json_encode(['code' => 1, 'msg' => '查询成功', 'data' => [
    'x' => $xData,
    'y' => $yData
]
]);